package com.llsydn.ndkdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

/**
 * @author lilinshen
 * @title JNI应用实例
 * @description 请填写相关描述
 * @date 2018/10/18 14:49
 */
public class MainActivity extends AppCompatActivity {
    private JavaCJNI javaCJNI;
    private CJavaJNI cJavaJNI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        javaCJNI = new JavaCJNI();
        cJavaJNI = new CJavaJNI();
        System.out.println("result===" + javaCJNI.sayHello());
    }

    public void add(View view) {
        int result = javaCJNI.add(99, 1);
        System.out.println(result);
    }

    public void string(View view) {
        String result = javaCJNI.lianJie("I am from java");
        System.out.println(result);
    }

    public void array(View view) {
        int array[] = {1, 2, 3, 4, 5};
        int result[] = javaCJNI.increaseArrayEles(array);
        for (int i = 0; i < result.length; i++) {
            System.out.println(result[i]);
        }
    }

    public void check(View view) {
        int result = javaCJNI.checkPwd("123");
        System.out.println(result);
    }

    public void addC(View view) {
        cJavaJNI.callbackAdd();
    }

    public void hello(View view) {
        cJavaJNI.callbackHello();
    }

    /**
     * c调用java，更新ui
     */
    public native void callbackCallUi();

    public void callUiClick(View view) {
        callbackCallUi();
    }

    public void callUi() {
        System.out.println("==c调用java==");
        Toast.makeText(MainActivity.this, "c调用java", Toast.LENGTH_SHORT).show();
    }

}
